package org.jcnc;

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;

public class SystemMonitorService {

    private final OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    public double getCpuLoad() {
        return osBean.getCpuLoad() * 100;  // 获取CPU负载百分比
    }

    public double getFreeMemory() {
        return osBean.getFreeMemorySize() / 1024.0 / 1024.0 / 1024.0;  // 获取剩余内存 (GB)
    }

    public double getTotalMemory() {
        return osBean.getTotalMemorySize() / 1024.0 / 1024.0 / 1024.0;  // 获取总内存 (GB)
    }

    public double getSwapUsed() {
        return osBean.getCommittedVirtualMemorySize() / 1024.0 / 1024.0 / 1024.0;  // 获取已使用交换内存 (GB)
    }

    public double getSwapTotal() {
        return osBean.getTotalSwapSpaceSize() / 1024.0 / 1024.0 / 1024.0;  // 获取总交换内存 (GB)
    }
}
